package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsGoodsSpecificationMapper;
import com.qf.pojo.DtsGoodsSpecification;
import com.qf.service.DtsGoodsSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author wanghaotian
 * time:2022/12/21,0021 9:32
 * description:
 */

@Service
public class DtsGoodsSpecificationServiceImpl implements DtsGoodsSpecificationService {

    @Autowired
    private DtsGoodsSpecificationMapper goodsSpecificationMapper;

    @Override
    public List<DtsGoodsSpecification> findSpecificationByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsSpecification> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsSpecification::getGoodsId,id);
        wrapper.eq(DtsGoodsSpecification::getDeleted,false);
        List<DtsGoodsSpecification> specifications = goodsSpecificationMapper.selectList(wrapper);
        return specifications;
    }

    @Override
    public void deleteByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsSpecification> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsSpecification::getGoodsId,id);
        goodsSpecificationMapper.delete(wrapper);
    }

    @Override
    public void insert(DtsGoodsSpecification specification) {
        specification.setDeleted(false);
        specification.setAddTime(new Date());
        specification.setUpdateTime(new Date());
        goodsSpecificationMapper.insert(specification);
    }
}
